<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2018-10-04
 * Time: 11:57
 */
namespace app\api\controller;

use app\common\controller\Apibase;
use app\common\model\Part as cxModel;

class Part extends Apibase{
    //
    public function getList(){
        $getdata = request()->param();
        $cxmodel = new cxModel();
        if(empty($getdata)){
            $this->error('非法访问！');
        }
        $getlist = $cxmodel->get_list($getdata);
        $getlist['code'] = '1';
        if(empty($getlist['list'])){
            $getlist['code'] = '0';
            return json($getlist);
        }
        if(!empty($getdata['count'])){
            $add = $getdata['count'].'count';
            foreach ($getlist['list'] as $k => $v){
                if(empty($getdata['so'])){
                    $v[$add] = db($getdata['count'])->where('aid',$v['aid'])->count();
                }else{
                    $v[$add] = db($getdata['count'])->where('aid',$v['aid'])->where($getdata['so'],$v[$getdata['so']])->count();
                }
                $newlist[$k] = $v;
            }
            $getlist['list'] = $newlist;
        }
        return json($getlist);
    }

    /**
     * 请求参数 mid,fid
     * 如mid为1001则跳过
     * 如fid为0则获取所有栏目
     * 返回数据 全部栏目列表 code= 0 OR 1 打包JSON数据
     * @return \think\response\Json
     */
    public function getPartlist(){
        $getdata = request()->param();
        $getdata = datatrim($getdata);
        $map = null;
        if($getdata['mid'] != '1001'){
            $map['mid'] = $getdata['mid'];
        }
        if($getdata['fid'] != '0'){
            $map['id'] = $getdata['fid'];
        }
        $cxmodel = new cxModel();
        $partlist = $cxmodel->api_getlist($map);
        $res['code'] = '1';
        $res['list'] = $partlist;
        if(empty($partlist)){
            $res['code'] = '0';
        }
        return json($res);
    }


}